let MS = require('./ms.js')
const request = require('./request.js')
const {
    isString,
    isNumber,
    isUndefined,
    isBoolean,
    isObject
} = require('./dataType')

const topic = class topic {
    constructor() {

    }

    findTopic(options) {
        let params = {}
        if(!isUndefined(options) && isObject(options)) {
            if(!isUndefined(options.title) && isString(options.title)) {
                params.title = options.title;
            }
            if(!isUndefined(options.isActivity) && isBoolean(options.isActivity)) {
                params.isActivity = options.isActivity;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.TOPIC.FIND_TOPIC.url,
                MS._config.parameters.TOPIC.FIND_TOPIC.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    query(options) {
        let params = {
            pageNum: 1,
            pageSize: 10
        }
        if(!isUndefined(options) && isObject(options)) {
            if(!isUndefined(options.title) && isString(options.title)) {
                params.title = options.title;
            }
            if(!isUndefined(options.isActivity) && isBoolean(options.isActivity)) {
                params.isActivity = options.isActivity;
            }
            if(!isUndefined(options.pageNum) && isNumber(options.pageNum)) {
                params.pageNum = options.pageNum;
            }
            if(!isUndefined(options.pageSize) && isNumber(options.pageSize)) {
                params.pageSize = options.pageSize;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.TOPIC.FIND_TOPIC_BY_VO.url,
                MS._config.parameters.TOPIC.FIND_TOPIC_BY_VO.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = topic